package conexiones;

import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.net.*;
import java.util.Enumeration;


import android.app.Activity;
import android.os.AsyncTask;
import android.os.Handler;
import android.util.Log;
import android.widget.TextView;

public class CrearSala implements Runnable { 
	int puerto;
	InetAddress ipCast;
	Activity act=null;
	Handler handler;
	public CrearSala(int port,Handler hand ,Activity actividad){
		puerto=port;
		act=actividad;
		handler=hand;
		
	}
  
    public void run() { 
        try { 
        	MulticastSocket ms=new MulticastSocket(puerto);
			InetAddress ip=InetAddress.getByName("225.69.69.85");
			ms.joinGroup(ip);
			byte buf[]=new byte[1000];
			DatagramPacket data=new DatagramPacket(buf, buf.length);
			ms.receive(data);
			String aux="";
			int i=0;
			while(buf[i]==0){
				aux+=buf[i];
				i++;
			}
			final String msg=aux;
            handler.post(new Runnable() { 
                @Override
                public void run() { 
//            		TextView tv=(TextView)act.findViewById(R.id.textView2);
//					tv.setText(msg);
                } 
            });
        } catch (Exception e) { 
            handler.post(new Runnable() { 
                @Override
                public void run() { 
//                	TextView tv=(TextView)act.findViewById(R.id.textView2);
//					tv.setText("error"); 
                } 
            }); 
            e.printStackTrace(); 
        } 
    }  
}
